const { Sequelize } = require('sequelize');

// 数据库配置
const sequelize = new Sequelize('lingxi_system', 'root', '888mei525', {
  host: 'localhost',
  dialect: 'mysql',
  timezone: '+08:00',
  logging: false
});

async function checkTableStructure() {
  try {
    await sequelize.authenticate();
    console.log('数据库连接成功');
    
    // 检查sales_orders表结构
    const [results] = await sequelize.query('DESCRIBE sales_orders');
    console.log('\nsales_orders表结构:');
    console.log('字段名\t\t类型\t\t\t允许NULL\t键\t默认值\t\t额外');
    console.log('--------------------------------------------------------------------------------');
    results.forEach(row => {
      console.log(`${row.Field}\t\t${row.Type}\t\t${row.Null}\t\t${row.Key}\t${row.Default || 'NULL'}\t\t${row.Extra}`);
    });
    
    // 检查是否有organization_id字段
    const hasOrgId = results.some(row => row.Field === 'organization_id');
    console.log(`\n是否有organization_id字段: ${hasOrgId ? '是' : '否'}`);
    
    await sequelize.close();
  } catch (error) {
    console.error('检查表结构时出错:', error.message);
  }
}

checkTableStructure();